package vn.fpt.fsoft.action.admin;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;
import org.springframework.web.struts.DispatchActionSupport;

import vn.fpt.fsoft.bl.ManageUsersBL;
import vn.fpt.fsoft.entity.AdminAccountInfo;

public class DoEditAdminAction extends DispatchActionSupport {
	public ActionForward editAdmin(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		AdminAccountInfo admin = null;
		try {
			ManageUsersBL manageUserBL = (ManageUsersBL) getWebApplicationContext()
					.getBean("ManageUserBL");
			DynaActionForm f = (DynaActionForm) form;
			admin = (AdminAccountInfo) f.get("admin");
			manageUserBL.updateChangedAdminUser(admin);

			if (admin.getRole() == 1) {
				return mapping.findForward("edit_admin_success");
			} else {
				return mapping.findForward("edit_contributer_success");
			}
		} catch (Exception ex) {
			if (admin.getRole() == 1) {
				return mapping.findForward("edit_contributer_failure");
			} else {
				return mapping.findForward("edit_contributer_failure");
			}
		}
	}

	public ActionForward editMember(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		return mapping.findForward("delete_user_success");
	}

}
